package com.wlwk.common.exception.util;

import com.wlwk.common.exception.menu.RespCode;

import java.util.HashMap;
import java.util.Map;

/**
 * 返回数据
 */
public class RespResult extends HashMap<String, Object> {
	private static final long serialVersionUID = 1L;

	public RespResult() {
		put("code", "0000");
		put("msg", "成功");
	}

	public static RespResult error() {
		return error("9999", "未知异常，请联系管理员");
	}

	public static RespResult error(String msg) {
		return error("9999", msg);
	}

	public static RespResult error(RespCode respCode) {
		RespResult r = new RespResult();
		r.put("code", respCode.getCode());
		r.put("msg", respCode.getMsg());
		return r;
	}

	public static RespResult error(String code, String msg) {
		RespResult r = new RespResult();
		r.put("code", code);
		r.put("msg", msg);
		return r;
	}

	public static RespResult ok(String msg) {
		RespResult r = new RespResult();
		r.put("msg", msg);
		return r;
	}


	public static RespResult ok(Map<String, Object> map) {
		RespResult r = new RespResult();
		r.putAll(map);
		return r;
	}

	public static RespResult ok() {
		return new RespResult();
	}

	@Override
	public RespResult put(String key, Object value) {
		super.put(key, value);
		return this;
	}
}
